<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<title>查看详情</title>
		<link href="/css/bootstrap.min.css" rel="stylesheet">
		<script type="text/javascript" src="/js/jquery-3.0.0.min.js"></script>
		<script src="/js/wangEditor.min.js"></script>
	</head>

	<body>
	<#include "/common/head.ftl" >
		<div class="container-fluid">
			<div class="row">
				<#include "/common/left.ftl" >
				<div class="col-sm-9">
					<ol class="breadcrumb">
						<li>
							<a href="#">主页</a>
						</li>
						<li class="active">问答详情</li>
					</ol>
					
					<div class="panel panel-info">
				  	  <div class="panel-heading">${qainfo.qatitle!}<p class="text-muted" style="float: right;">${qainfo.qatype!} ${qainfo.publisher.name}发布于${qainfo.createtime!}</p></div>
					  <div class="panel-body">
						${qainfo.qadetail}
					  </div>
					</div>
					<#list qainfo.solutions as solution>
					<#if solution_index==0>
						<div class="panel panel-success">
						  <div class="panel-heading">主要解决方案</div>
						  <div class="panel-body">
							  ${solution.solution}
							  <span class="badge" onclick="ding('${solution.id}',this)"><span class="glyphicon glyphicon-thumbs-up"></span> <span class="dingtxt">${solution.ding}</span></span>
							  <span class="badge" onclick="cai('${solution.id}',this)"><span class="glyphicon glyphicon-thumbs-down"></span> <span class="caitxt">${solution.cai}</span></span>
						  </div>
						</div>
					<#else>
						<div class="panel panel-warning">
							<div class="panel-heading">其他解决方案</div>
							<div class="panel-body">
								${solution.solution}
								<span class="badge" onclick="ding('${solution.id}',this)"><span class="glyphicon glyphicon-thumbs-up"></span> <span class="dingtxt">${solution.ding}</span></span>
								<span class="badge" onclick="cai('${solution.id}',this)"><span class="glyphicon glyphicon-thumbs-down"></span> <span class="caitxt">${solution.cai}</span></span>
							</div>
						</div>
					</#if>
					</#list>
					<form class="form-horizontal" action="/qa/addsolution" method="post" onsubmit="return checkform()">
						<input type="hidden" name="qaInfo.id" value="${qainfo.id}"/>
						<div class="form-group">
							<label for="mysolution" class="col-sm-2 control-label">你的解决方案</label>
							<div class="col-sm-10">
								<div id="div1">
								</div>
								<textarea class="form-control" name="solution" style="display: none" id="mysolution"></textarea>
							</div>
						</div>
						<div class="form-group">
							<div class="col-sm-offset-2 col-sm-10">
								<button type="submit" class="btn btn-primary">提交</button>
							</div>
						</div>
					</form>
				</div>
			</div>
		</div>
		<script>
			var E = window.wangEditor
			var editor = new E('#div1')
			var $text1 = $('#mysolution')
			editor.customConfig.onchange = function (html) {
				// 监控变化，同步更新到 textarea
				$text1.val(html)
			}
			editor.create()
			// 初始化 textarea 的值
			$text1.val(editor.txt.html())

			function checkform(){
				if($text1.val()=="<p><br></p>"){
					alert("请输入内容！");
					return false;
				}
				return true;
			}

			function ding(sid,dspan){
				$.post("/qa/dingcai","sid="+sid+"&dingcai=1",function (r) {
					if(!isNaN(r)){
						$(dspan).children(".dingtxt").text(r);
					}else{
						alert(r);
					}
				});
			}
			function cai(sid,dspan){
				$.post("/qa/dingcai","sid="+sid+"&dingcai=0",function (r) {
					if(!isNaN(r)){
						$(dspan).children(".caitxt").text(r);
					}else{
						alert(r);
					}
				});
			}
		</script>
	</body>

</html>